<%@ page contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ include file="/common/init.jsp"%>
<script src="<c:url value='/resources/js/jquery-1.7.2.min.js"'/>"></script>
<link href="<c:url value='/admin/css/custom.css'/>" rel="stylesheet" type="text/css" />
<link href="<c:url value='/admin/css/style.css'/>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<c:url value='/resources/js/mask.js'/>"></script>
<style type="text/css">
<!--
body {
	background: #ffffff;
	margin-top:10px;
	margin-left:5px;
	margin-right:5px;
}
-->
</style>
<body><!-- EP交易中的申诉 -->
<div class="EpmsSubTitle"><p><b>EP管理</b></p>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="EpmsTable">
  <tr>
	  <td class=EpmsTdTitle>卖家</td>
	  <td class=EpmsTdTitle>买家</td>
	  <td class="EpmsTdTitle">金额</td>
	  <td class="EpmsTdTitle">手续费</td>
	  <td class="EpmsTdTitle">汇款费</td>
	  <td class=EpmsTdTitle>状态</td>
	  <td class=EpmsTdTitle>操作</td>
	  <td class=EpmsTdTitle>确认时间</td>
	  <td class=EpmsTdTitle>投诉</td>
  </tr>
	<c:forEach var="ep" items="${epList}">
		<tr>
			<td class=EpmsTdNoColor align="center">${ep['user_id']}</td>
		    <td class=EpmsTdNoColor align="center">${ep['relation_id']} &nbsp;</td>
			<td class="EpmsTdNoColor" align="center">
				${ep['deal_amount']}
			</td>
			<td class="EpmsTdNoColor" align="center">
				${ep['charge_fee']}
			</td>
			<td class="EpmsTdNoColor" align="center">
				${ep['post_fee']}
			</td>
			<td class="EpmsTdNoColor" align="center">
				<c:if test="${'1' eq ep['status']}">卖出</c:if>
				<c:if test="${('2' eq ep['status']) && ('1' eq ep['type'])}">买方未汇款</c:if>
				<c:if test="${('2' eq ep['status']) && ('2' eq ep['type'])}">
				买方汇款，卖方未确认
				</c:if>
				<c:if test="${'3' eq ep['status']}">交易完成</c:if> &nbsp;
			</td>
			<td class="EpmsTdNoColor">
			<c:if test="${'2' eq ep['status']}">
				<input type="button" value="支持卖方" onclick="supportSale('${ep['id']}','${ep['user_id']}');"/>
				<input type="button" value="支持买方" onclick="supportBuy('${ep['id']}','${ep['relation_id']}');"/>
			</c:if>
			<c:if test="${'1' eq ep['status']}">
				<input type="button" value="取消" onclick="epcancel('${ep['id']}');"/>
			</c:if>
			 &nbsp;
			</td>
		    <td class=EpmsTdNoColor align="center">
		    	<fmt:formatDate value="${ep['success_date']}" pattern="yyyy-M-dd HH:mm:ss"/>&nbsp;
		    </td>
		    <td class=EpmsTdNoColor>
			    <c:if test="${(not empty ep['complainId']) && (ep['handle'] == '1')}">
			    	<a href="${ctx}/admin/complain.action?id=${ep['complainId']}">投诉</a>
			    </c:if>
			    <c:if test="${ep['handle'] == '0'}">
			    	<a href="${ctx}/admin/complain.action?id=${ep['complainId']}">投诉已处理</a>
			    </c:if> &nbsp;
		    </td>
		</tr>
	</c:forEach>
	<tr>
		<td class="EpmsTdNoColor" colspan="9" align="right">
		第${pageNo}页&nbsp;&nbsp;
			<c:choose>
			<c:when test="${pageNo >1}">
				<a href="javascript:void(0);" style="text-decoration: none;">
					<span onclick="frontpage(${pageNo-1})">上一页</span>&nbsp;
				</a>
			</c:when>
			<c:otherwise>
				上一页 &nbsp;
			</c:otherwise>
			</c:choose>
			<c:choose>
				<c:when test="${totalPage> pageNo}">	
					<a href="javascript:void(0);" style="text-decoration: none;">
						<span onclick="nextpage(${pageNo+1})">下一页</span> &nbsp;
					</a>
				</c:when>
				<c:otherwise>
					下一页&nbsp;
				</c:otherwise>
			</c:choose>
			&nbsp;共${totalPage}页&nbsp;&nbsp;共${totalCount}页
		</td>
	</tr>
</table>
</body>
<script type="text/javascript">

function supportSale(eid, userid){
	//user_id
	if(window.confirm("确认要将该EP交易中的款项添加到卖方账户吗？")){
		$(document).mask("系统处理中，请稍后......");
		$.post("supportep.action", {type: "1",id: eid,account:userid },function(data,status){
		    if($.trim(data) == '1'){
		    	alert("操作成功！");
		    	window.location.href = "eplist.action";
		    }else{
		    	alert("操作失败，请重试！");
		    	window.location.href = "eplist.action";
		    }
		});
	}
}

function supportBuy(eid, userid){
	//relationId
	if(window.confirm("确认要将该EP交易中的款项添加到买方账户吗？")){
		$(document).mask("系统处理中，请稍后......");
		$.post("supportep.action",{type: "2",id: eid,account:userid },function(data,status){
		    if($.trim(data) == '1'){
		    	alert("操作成功！");
		    	window.location.href = "eplist.action";
		    }else{
		    	alert("操作失败，请重试！");
		    	window.location.href = "eplist.action";
		    }
		});
	}
}

function epcancel(id){
	if(confirm("您确定要取消该用户的ep交易吗?")){
		//取消ep交易
		$(document).mask("系统处理中，请稍后......");
		$.ajax({
			type: 'POST',
			url: '${ctx}/epcancel.action',
			data: 'id='+id,
			dataType:'html',
			success:function(data){
				alert($.trim(data));
   				window.location.href="${ctx}/admin/eplist.action";
			},
			error:function(data, status, e){
				
			}
		});
	}
}

function frontpage(pageNo){
	location = "${ctx}/admin/eplist.action?pageNo="+pageNo;
}

function nextpage(pageNo){
	location = "${ctx}/admin/eplist.action?pageNo="+pageNo;
}
</script>